//
//  SQLController.swift
//  test-ios
//
//  Created by wyz5204 on 2023/3/20.
//

import UIKit
import ReactiveCocoa
import ReactiveSwift


class SQLController: ABaseViewController , UITableViewDataSource , UITableViewDelegate{
    
    // 使用table view
    
    /*
      插入数据全检查
     INSERT INTO table (field1, field2, fieldn)
         SELECT 'field1', 'field2', 'fieldn' FROM DUAL
             WHERE NOT EXISTS(SELECT field FROM table WHERE field = ?)
     */
    private lazy var tableView = {
        return UITableView()
    }()
    
    private var sqlArray = ["FMDB" , "SQLite.swift" , "GRDB.swift"]
    
    
    override func loadView() {
        super.loadView()
        
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        tableView.addTo(self.view) {[weak self] view in
            view.dataSource = self
            view.delegate = self
            view.register(TextCell.self, forCellReuseIdentifier: "cell")
            view.snp.makeConstraints { make in
                make.edges.equalToSuperview()
            }
        }
        
    }
    
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return sqlArray.count
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print("点击了" , sqlArray[indexPath.row])
        switch(sqlArray[indexPath.row]){
        case sqlArray[2] :
            startViewController(GRDBViewController())
        default:
            break
        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 100
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! TextCell
        cell.initBinder( tableView , sqlArray[indexPath.row] , indexPath)
        return cell
        
    }
}
